package com.ruoyi.consumer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consumer.domain.CRequirement;
import com.ruoyi.consumer.service.ICRequirementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * requirementController
 * 
 * @author ruoyi
 * @date 2023-11-13
 */
@RestController
@RequestMapping("/consumer/requirement")
public class CRequirementController extends BaseController
{
    @Autowired
    private ICRequirementService cRequirementService;

    /**
     * 查询requirement列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:requirement:list')")
    @GetMapping("/list")
    public TableDataInfo list(CRequirement cRequirement)
    {
        startPage();
        List<CRequirement> list = cRequirementService.selectCRequirementList(cRequirement);
        return getDataTable(list);
    }

    /**
     * 导出requirement列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:requirement:export')")
    @Log(title = "requirement", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CRequirement cRequirement)
    {
        List<CRequirement> list = cRequirementService.selectCRequirementList(cRequirement);
        ExcelUtil<CRequirement> util = new ExcelUtil<CRequirement>(CRequirement.class);
        util.exportExcel(response, list, "requirement数据");
    }

    /**
     * 获取requirement详细信息
     */
    @PreAuthorize("@ss.hasPermi('consumer:requirement:query')")
    @GetMapping(value = "/{requireId}")
    public AjaxResult getInfo(@PathVariable("requireId") Integer requireId)
    {
        return success(cRequirementService.selectCRequirementByRequireId(requireId));
    }

    /**
     * 新增requirement
     */
    @PreAuthorize("@ss.hasPermi('consumer:requirement:add')")
    @Log(title = "requirement", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CRequirement cRequirement)
    {
        return toAjax(cRequirementService.insertCRequirement(cRequirement));
    }

    /**
     * 修改requirement
     */
    @PreAuthorize("@ss.hasPermi('consumer:requirement:edit')")
    @Log(title = "requirement", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CRequirement cRequirement)
    {
        return toAjax(cRequirementService.updateCRequirement(cRequirement));
    }

    /**
     * 删除requirement
     */
    @PreAuthorize("@ss.hasPermi('consumer:requirement:remove')")
    @Log(title = "requirement", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requireIds}")
    public AjaxResult remove(@PathVariable Integer[] requireIds)
    {
        return toAjax(cRequirementService.deleteCRequirementByRequireIds(requireIds));
    }
}
